#ifndef UDPCLIENT_H
#define UDPCLIENT_H

#include <QObject>
#include <QUdpSocket>
#include <QThread>
#include <QDebug>
#include <QHostAddress>
#include "QmlSignal.h"
#include <CommonHelper.h>
#include "animationManager.h"
#include <ExperimentThread.h>
#include <LogHelper.h>
#include <CommCommand.h>
#include <QDateTime>

//该对象最终运行在次线程中
class UdpClient : public QUdpSocket
{
    Q_OBJECT
public:
    static UdpClient* getInstance();
    UdpClient(QObject *parent = NULL);
    ~UdpClient();
public:
    void ClientConnectToHost(const QString &address, quint16 port);
    void ClientSendingData(const QByteArray &c_btaData);
    bool IsOnline();

signals:
    //转换来自主线程的链接操作
    void SignalConnectToHost(const QString & address, quint16 port);
signals:
    //转换来自主线程的发送操作
    void SignalSendingData(const QByteArray c_btaData);
signals:
    //在次线程中缓冲并滑动解析TCP流后/按约定格式再发布
    void SignalPublishFormatRecvData(const QString c_btaData);

private:
    void receiveDataProcessing(QStringList);
    void saveLog(QString,QStringList);

private:
    //标记连接情况
    bool m_bOnLine = false;
    static UdpClient* Instance ;
    CommonHelper* common;
    QByteArray backSendData;
    Loghelper *logClient;
};

#endif // UDPCLIENT_H
